home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / demos / mastdemo.zoo / batch / macros.bat < prev    next >
DOS Batch File  |  1990-03-22  |  6KB  |  197 lines

  1. #--------- Initialisations for Master instead of a Save-File ------------------
  2.  
  3. # This batchfile includes some useful macros. It can be used as an
  4. # initialisation file for Master or as an example for your own batchfiles.
  5. # It is useful to have such a batchfile beside the normal Master-SAVE-file.
  6. # A batchfile is easier to maintain and is a good reference when printed.
  7.  
  8. rem MASTER-Initialisation started
  9.  
  10. Unix;                # because we use / as Directorydelimiter
  11. alias setdir    'set \$1 \$2';    # local, allows arbitrary TABS in SET command
  12.  
  13. #-------------------------- status-variables -----------------------------------
  14. rem status-variables
  15.   Alarm        wait
  16. noDelimiter
  17. noDostrace
  18. noEcho
  19.   Hold
  20.   Home        /master
  21. noNorec
  22.   Magic
  23.   Path        /tools,/batch,$HOME
  24.   Prompt    black \; rem \; datetime \; cd \=> cwd \; rem (\$cwd) 
  25. noQuiet
  26.   Sign_on    ls
  27.   Sort        time
  28. noTalk
  29.   Unix        6;    # * as searchstring for all files, / in XARGS
  30. noUserred
  31. #  Varsize    100000;    # allow large pipes
  32.   Virgin    12;    # no Master-wildcards in programs, keyboard redefinable
  33.   Wrap
  34.   Xargs        14;    # Atari standard ARGV & xArg, filehandle 2 = CON:
  35.  
  36. #------------------------ control structures -----------------------------------
  37. rem control structures
  38.  
  39. # nextitem list variable - takes the next value out of the list
  40. alias nextitem    'car \$1 => \$2; cdr \$1 => \$1'
  41.  
  42. # increment variable - increments the numerical value of variable by 1
  43. # decrement variable - decrements the numerical value of variable by 1
  44. alias increment    'eval \$1 1 + => \$1'
  45. alias decrement    'eval \$1 1 - => \$1'
  46.  
  47. # this little trick allows you to get the list of all active drives
  48. alias alldrives    '{lock => locked; lock A B C D E F G H I J K L M N O P; lock; unlock -o; lock \$locked -> locked;}'
  49.  
  50. # the following 3 macros are short forms of some often used tests
  51. # Usage: 'ifxyz variable { ...'
  52. alias ifglobal    if not exec "set? -g \$1" \$+
  53. alias iflocal    if not exec "set? -l \$1" \$+
  54. alias ifempty    if exec "{car \$1 => tmp; if tmp = '' {err 1;}}" \$+
  55.  
  56. # Not all possible loop constructs are realized in Master. But they can be
  57. # programmed as alias. The following examples prove this.
  58.  
  59. # repeat
  60. #    statements
  61. # until test
  62. alias repeat    'loop {'
  63. alias until    'if \$* {break;}}'
  64.  
  65. # foreach variable in list do
  66. #     statements with variable as 'loopcounter'
  67. # endfor
  68. alias foreach    'loop { ifempty \$3 {break;} nextitem \$3 \$1;:'
  69. alias endfor    }
  70.  
  71. # Other control structures like this case in the form of C are possible.
  72.  
  73. # switch variable
  74. #     case test value {
  75. #         statements
  76. #         [ endcase ]
  77. #     }
  78. #     ...
  79. # endswitch
  80. # test can be almost every usual if test:
  81. #     case == var
  82. #    case <> var
  83. #    case != var
  84. #    case in var
  85. #    ...
  86. # (but not: `eof file' or `exists file')
  87. alias switch    '{ set switchvar \$1; set switching yes'
  88. alias endswitch    }
  89. alias case    'if switching == "yes" && \$switchvar \$1 "\$2" \$+'
  90. alias endcase    set switching no
  91.  
  92. #------------------ links for toplevel directories -----------------------------
  93. kbd nobell    ;# no beep at the end of the toplink batch
  94. if "$1" != "" {
  95. # get our starting directory
  96.     set xx $@
  97.     setenv WORDENTITY /
  98.     set xx $xx[,-2]
  99.     unsetenv WORDENTITY
  100. # toplink should be in the same directory
  101.     $xx/toplink.bat
  102.     unset xx
  103. }
  104. kbd bell
  105.  
  106. #-------------------- short forms for Directories ------------------------------
  107.  
  108. setdir tdir    /tools
  109.  
  110. #------------------------- other aliases ---------------------------------------
  111. rem other aliases
  112. # for programs without ARGV or xArgs
  113. alias expand    '{set x \$*; cdr x => x; files -k200 \$x => x; \$1 \$x;}'
  114.  
  115. # if Master is several times in memory, this can be useful
  116. alias toplevel    Alias bye rem TOPLEVEL
  117. alias save    'unalias bye; Save'
  118.  
  119. # It is useful to include a line like 'cd $workdir' in STARTUP.BAT, so that
  120. # this alias allows you to continue with your work where you have finished.
  121. alias worksave    'cd => workdir; save'
  122.  
  123. # The following 3 shortcuts are easier to type
  124. alias ++    pushd
  125. alias --    popd
  126. # To clear the whole stack (note the tail-recursion)
  127. alias ---    'if not exec "popd" {---;}'
  128.  
  129. # For absolute unix-freaks. The comment lets you use this only for showing all
  130. # environment vars and not as an alias for setenv.
  131. alias @        'setenv;:'
  132.  
  133. # Dangerous commands should ask the user before they do something irreversible
  134. alias rm    Rm -i
  135. alias touch    Touch -i
  136.  
  137. # Send output to the printer
  138. alias lpr    'cat >prn:'
  139.  
  140. alias ll    Ll -u
  141. alias ls    Ls -un
  142. alias l        ls
  143. alias h        history -t
  144.  
  145. # Who always has the clock set correctly wants to know when a file was created
  146. # not whn it was last copied.
  147. alias cp    Cp -t
  148. alias mv    Mv -t
  149. alias pack    Pack -t
  150. alias unpack    Unpack -t
  151.  
  152. # The following alias is used in the PROMPT-string
  153. alias datetime    '{date => x;time => y;show -m => z;printf "%s, %s\\t\\t%s" x y "$z[6]";}'
  154.  
  155. # A simple screen saver for monochrome display
  156. alias wait    'inverse; cls; get => x; normal; cls'
  157.  
  158. # With the next alias in the prompt it's easier to use the previous one as
  159. # alarm to turn the monitor dark after some time.
  160. alias black    'if ALARMTIME != "" { chrono \$ALARMTIME > NUL:; }'
  161.  
  162. set ALARMTIME    00:05:00
  163.  
  164. # If you want to execute a program in a special directory (because you don't
  165. # use symbolic links) the following macro helps. After the work is done it
  166. # goes back to the current directory.
  167. # Usage: 'do directory command parameters'
  168. alias do    'pushd \$1; \$+; popd'
  169.  
  170. # With status variables it's a little bit tricky to save and restore the old
  171. # state. The following macro does the job. Note the semicolons before '}'. They
  172. # are absolutely necessary.
  173. # Usage: 'state statusvar variable'
  174. alias state    'cdr -0g \$1 => \$2; ifempty \$1 {set \$2 1; } else {eval \${\$2} => \$2; }'
  175.  
  176. # And this is a first application of state. The program runs in Virgin-Mode
  177. # (perhaps needed if you want to run a program that permanently changes the
  178. # gemdos or bios-traps, normally these are restored by Master).
  179. # Usage: 'virdo program params'
  180. alias virdo    '{state VIRGIN old; virgin; \$*; virgin \$old;}'
  181.  
  182. alias mouse    ~tdir/mouse.tos
  183.  
  184. key  F10    save@
  185. key   F4    wait@
  186.  
  187. key  +F9    mouse@
  188. key   F9    ~tdir/desk@
  189.  
  190. export            ;# make SET-variables visible in the outer world
  191.  
  192. #-------------------------------------------------------------------------------
  193.  
  194. unalias setdir        ;# we no longer need this
  195.  
  196. rem initialisation completed
  197.